﻿using IBMU2.UODOTNET;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mvLibrary.Helpers.Querys
{
    public class SubroutineManager
    {

        private static SubroutineManager instance;
        private SubroutineManager()
        {
        }

        public static SubroutineManager Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new SubroutineManager();
                }
                return instance;
            }
        }


        public UniSubroutine CreateSubRoutine(UniSession uniSession, string subRoutineName, params string[] subRoutineArguments)
        {
            UniSubroutine subRoutine = uniSession.CreateUniSubroutine(subRoutineName, subRoutineArguments.Count());
            int argumentIndex = 0;
            foreach (var argument in subRoutineArguments)
            {
                string value = argument ?? string.Empty;

                subRoutine.SetArg(argumentIndex++, value);
            }


            subRoutine.Call();

            return subRoutine;
        }
    }
}
